<template>
  <div id="changePassword">
    <el-form ref="form"
             :model="form"
             label-width="80px">
      <el-form-item label="手机号:" required>
        <el-input v-model="form.phone" disabled></el-input>
      </el-form-item>
      <el-form-item label="验证码:" required style="position: relative">
        <el-input v-model="form.code"></el-input>
        <el-button class="code" type="primary" @click="getCode">获取</el-button>
      </el-form-item>
<!--      <el-form-item label="旧密码:" required style="position: relative">-->
<!--        <el-input v-model="form.password"></el-input>-->
<!--        <el-link :underline="false" class="code" style="width: 80px">忘记密码？</el-link>-->
<!--      </el-form-item>-->
      <el-form-item label="新密码:" required>
        <el-input type="password" v-model="form.newPassword"></el-input>
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="save">
      保存
    </el-button>
  </div>
</template>

<script>
  import axios from "axios";

  export default {
    name: "ChangePassword",
    mounted() {
      if(this.$store.getters.getUserType == 'buyer')
      {
        this.form.phone = this.$store.getters.getInfo.ber_phone
      }
      else{
        this.form.phone = this.$store.getters.getInfo.ser_phone
      }
    },
    data(){
      return{
        form:{
          phone:'',
          code:'',
          // password:'',
          newPassword:''
        },
        isEdit:false
      }
    },
    methods:{
      getCode(){
        if(this.form.phone.length === 0){
          alert('请填写手机号！')
          return;
        }
        let params = {}
        params.phone = this.form.phone
        params.user = 'SERVICE'
        alert('验证码已发送，注意查收！')

        axios.post('https://haotry.top/api/verify/changePasswordVerification',JSON.stringify(params),{
          headers:{
            'Content-Type':'application/json'
          }
        }).then(res => {
          console.log(res)
          let data = res.data
          if(data.status === 200){
            console.log(data)
          }
        })
      },
      save(){
        axios.post('https://haotry.top/api/serviceSide/changePassword',JSON.stringify(this.form),{
          headers:{
            'Content-Type':'application/json'
          }
        }).then(res => {
          let data = res.data
          if(data.status === 200){
            console.log(data)
            alert('更换密码成功!')
            this.$router.push('/server/account/company')
          }
          else{
            alert(data.msg)
          }
        })
      }
    }
  }
</script>

<style scoped>
#changePassword{
  margin: 20px;
  width: 500px;
}
  .code{
    position: absolute;
    top: 0;
    left: 430px;
  }
</style>